/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once

#include "highfive/H5File.hpp"

#include "DBManager/IRepository/Input/Material/IOrthotropic2DMaterialRepository.h"
#include "DBManager/Repository/HDF5/Base/SingleRepositoryBase.h"

/* SG_DBMANAGER_HDF5_NAMESPACE_OPEN
namespace MAT8
{
    struct IDENTITY
    {
        SG::DataStructure::Common::Id      m_id       = 0;
        SG::DataStructure::Common::Real m_E1       = 0.0;  ///< x/1方向弹性模量
        SG::DataStructure::Common::Real m_E2       = 0.0;  ///< y/2方向弹性模量
        SG::DataStructure::Common::Real m_nu12     = 0.0;  ///< 泊松比
        SG::DataStructure::Common::Real m_G12      = 0.0;  ///< 平面内剪切模量
        SG::DataStructure::Common::Real m_G1Z      = 0.0;  ///< x-Z/1-Z剪切模量
        SG::DataStructure::Common::Real m_G2Z      = 0.0;  ///< y-Z/2-Z剪切模量
        SG::DataStructure::Common::Real m_rho      = 0.0;  ///< 密度
        SG::DataStructure::Common::Real m_A1       = 0.0;  ///< x/1方向热膨胀系数
        SG::DataStructure::Common::Real m_A2       = 0.0;  ///< y/2方向热膨胀系数
        SG::DataStructure::Common::Real m_tref     = 0.0;  ///< 参考温度
        SG::DataStructure::Common::Real m_XT       = 0.0;  ///< x/1方向拉伸强度极限
        SG::DataStructure::Common::Real m_XC       = 0.0;  ///< x/1方向压缩强度极限
        SG::DataStructure::Common::Real m_YT       = 0.0;  ///< y/2方向拉伸强度极限
        SG::DataStructure::Common::Real m_YC       = 0.0;  ///< y/2方向压缩强度极限
        SG::DataStructure::Common::Real m_S       = 0.0;  ///< 剪切强度极限
        SG::DataStructure::Common::Real m_ge       = 0.0;  ///< 单元阻尼
        SG::DataStructure::Common::Real m_F12      = 0.0;  ///< Tsai-Wu 交叉项系数
        SG::DataStructure::Common::Real m_Stan     = 0.0;  /// m_XT - m_Yc 对应的是应力还是应变的强度极限
        SG::DataStructure::Common::Id      m_domainId = 0;
    };
    struct MAT8HSN
    {
        SG::DataStructure::Common::Id      MID        = 0;
        char                            HFAI[4]    = "";
        char                            xHFAIL[4]  = "NO";
        SG::DataStructure::Common::Real HF1        = 0.0;
        SG::DataStructure::Common::Real HF2        = 0.0;
        SG::DataStructure::Common::Real HF3        = 0.0;
        SG::DataStructure::Common::Real HF4        = 0.0;
        SG::DataStructure::Common::Real HF10       = 0.0;
        SG::DataStructure::Common::Real HF11       = 0.0;
        char                            HTAP[4]    = "";
        char                            xHTAPE[4]  = "NO";
        SG::DataStructure::Common::Real HT1        = 0.0;
        SG::DataStructure::Common::Real HT2        = 0.0;
        SG::DataStructure::Common::Real HT3        = 0.0;
        SG::DataStructure::Common::Real HT4        = 0.0;
        SG::DataStructure::Common::Real HT5        = 0.0;
        SG::DataStructure::Common::Real HT6        = 0.0;
        SG::DataStructure::Common::Real HT10       = 0.0;
        SG::DataStructure::Common::Real HT11       = 0.0;
        SG::DataStructure::Common::Real HT12       = 0.0;
        char                            HFAB[4]    = "";
        char                            xHFABR[4]  = "NO";
        SG::DataStructure::Common::Real HFB1       = 0.0;
        SG::DataStructure::Common::Real HFB2       = 0.0;
        SG::DataStructure::Common::Real HFB3       = 0.0;
        SG::DataStructure::Common::Real HFB4       = 0.0;
        SG::DataStructure::Common::Real HFB5       = 0.0;
        SG::DataStructure::Common::Real HFB6       = 0.0;
        SG::DataStructure::Common::Real HFB10      = 0.0;
        SG::DataStructure::Common::Real HFB11      = 0.0;
        SG::DataStructure::Common::Real HFB12      = 0.0;
        SG::DataStructure::Common::Id      m_domainId = 0;
    };
}  // namespace MAT8
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE */

// template <>
// inline HighFive::DataType HighFive::create_datatype<SG::DataStructure::FEM::MAT8HSN> ()
// {
//     HighFive::CompoundType compoundType = {
//         { "MID", HighFive::create_datatype<SG::DataStructure::Common::Id> () },
//         { "HFAI", HighFive::create_datatype<char[4]> (), 1, true },
//         { "xHFAIL", HighFive::create_datatype<char[4]> (), 1, true },
//         { "HF1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HF2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HF3", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HF4", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HF10", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HF11", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HTAP", HighFive::create_datatype<char[4]> (), 1, true },
//         { "xHTAPE", HighFive::create_datatype<char[4]> (), 1, true },
//         { "HT1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT3", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT4", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT5", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT6", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT10", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT11", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HT12", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFAB", HighFive::create_datatype<char[4]> (), 1, true },
//         { "xHFABR", HighFive::create_datatype<char[4]> (), 1, true },
//         { "HFB1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB3", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB4", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB5", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB6", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB10", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB11", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "HFB12", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
//         { "DOMAIN_ID", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
//     };
//     return compoundType;
// }

template <>
inline HighFive::DataType HighFive::create_datatype<SG::DataStructure::FEM::Orthotropic2DMaterial> ()
{
    HighFive::CompoundType compoundType = { { "MID", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "E1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "E2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "NU12", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "G12", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "G1Z", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "G2Z", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "RHO", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "A1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "A2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "TREF", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "XT", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "XC", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "YT", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "YC", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "S", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "GE", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "F12", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "STRN", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DOMAIN_ID", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "HFAILFactor", HighFive::create_datatype<SG::DataStructure::Common::Real[6]> (), 8, true },
                                            { "HTAPEFactor", HighFive::create_datatype<SG::DataStructure::Common::Real[9]> (), 8, true },
                                            { "HFABRFactor", HighFive::create_datatype<SG::DataStructure::Common::Real[9]> (), 8, true } };

    return compoundType;
}

SG_DBMANAGER_HDF5_NAMESPACE_OPEN
class Orthotropic2DMaterialRepository : public IOrthotropic2DMaterialRepository,
                                        public SingleRepositoryBase<SG::DataStructure::FEM::Orthotropic2DMaterial>
{
  public:
    enum DATASET : std::uint8_t
    {
        MainDataset,
        IndexDataset,
        SubDataset
    };

    explicit Orthotropic2DMaterialRepository (HDF5Database& database);

    void InitialDatasetInfo () override;

    // void DumpWriteCahce () override;

    // std::vector<DataType>* LoadReadCache (std::size_t loadIndex) override;

    // void SortData () override;

    // /**
    //  * @brief   : 将自己的数据转存为nastran的数据结构
    //  */
    // void OwnToNastran (std::vector<SG::DataStructure::FEM::Orthotropic2DMaterial>& own,
    //                    std::vector<SG::DBManager::HDF5::MAT8::IDENTITY>& _OUT      IDENTITYData,
    //                    std::vector<SG::DBManager::HDF5::MAT8::MAT8HSN>& _OUT       subData);

    // /**
    //  * @brief   : 将NASTRAN的数据转存为自己的数据结构
    //  * @param   : IDENTITY
    //  * @param   : INFO
    //  * @param   : own
    //  */
    // void NastranToOwn (std::vector<SG::DBManager::HDF5::MAT8::IDENTITY>&                IDENTITYData,
    //                    std::vector<SG::DBManager::HDF5::MAT8::MAT8HSN>&                 subData,
    //                    std::vector<SG::DataStructure::FEM::Orthotropic2DMaterial>& _OUT own);
};
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
